package com.yang.utils;

import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author yangdacheng
 * @title: RedisFactoryUtils
 * @projectName note_api
 * @description: TODO
 * @date 2022/3/24 5:19 下午
 */
@Component
public class RedisFactoryUtils {

    @Resource
    private RedisTemplate redisTemplate;

    /**
     * 添加新的元素
     * @param tableName
     * @param value
     */
    public void insetToList(String tableName,String value){
        if (!findValueInList(tableName, value)){
            redisTemplate.opsForList().rightPush(tableName,value);
        }
    }

    /**
     *
     * @param table
     * @param value
     * @return
     */
    public Boolean findValueInList(String table,String value){
        return redisTemplate.opsForList().indexOf(table, value)!=null;
    }
}
